﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TankHP : MonoBehaviour {

    public int HP = 100;//总的血量
    public GameObject TankExp;
    public AudioClip Tankexp;

    public Slider BG;//血条显示

    private int allhp;//当前血量

	void Start () {
        allhp = HP;
	}

    void isTank()
    {
        if (HP <= 0) return;      

        HP -= Random.Range(5, 15);
        BG.value = (float)HP / allhp;

        if (HP<=0)
        {
            GameObject.Instantiate(TankExp, transform.position + Vector3.up, transform.rotation);
            AudioSource.PlayClipAtPoint(Tankexp, transform.position);
            GameObject.Destroy(this.gameObject);
        }
    }
}
